package com.yy.QSManage.api.other;

import com.yy.QSManage.common.Result;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/ApplicationRestarterApi")
@Api(tags = "重启")
public class ApplicationRestarter {

    @GetMapping("/restart")
    public Result<String> triggerRestart() throws IOException {
        Path triggerFile = Paths.get(  System.getProperty("user.dir"),  // 项目根目录
                "target",
                "classes",
                "restart.trigger");

        // 写入包含时间戳的内容，确保每次不同
        String content = "restart-" + LocalDateTime.now();
        Files.write(triggerFile, content.getBytes());

        return Result.success("Restart triggered via trigger file!");
    }

}
